/**
 * 权限相关的数据
 * Created by gcc on 2017/9/29.
 */


const tableRowActionEdit = function (self) {
  return {
    title: '操作',
    key: 'action',
    width: 200,
    align:"center",
    render: (h, params) => {
      return (
        <div>
          < i-button type="primary" size="small"  style="margin-right:10px" onClick={() => {self.editItem(params.index)}}>编辑</i-button>
          < i-button type="error" size="small"  style="margin-right:10px" onClick={() => {self.deleteAction(params.index)}}>删除</i-button>
        </div>
      );
    }
  }
};

// 页码相关
let page = {
  total: 1,
  startIndex: 0,
  stepNumber: 20,
  currentPage: 1
};

//页面状态相关
let status = {
  //新建或编辑 的弹出框
  modalModify: {
    isShow: false,
    isModify: false,
    title: "",
    isLoading: true,
  },
  //删除员工的 modal
  modalDelete: {
    isShow: false,
    isLoading: false,
    //待删除的功能信息
    action: {
      id: '',
      name:''
    }
  },
  rules: {
    name: [
      {required: true, message: '功能名称不能为空', trigger: 'blur'}
    ],
    id: [
      {required: true, type: 'integer',message: '模块编号必须为数字',trigger: 'blur'},
      { type: 'integer', min: 1, message: '模块编号不能小于0', trigger: 'change' },
      { type: 'integer', max: 999999999, message: '模块编号太长', trigger: 'change' }
    ],
    sequence: [
      {required: true, type: 'integer',message: '模块编号必须为数字',trigger: 'blur'},
      { type: 'integer', min: 1, message: '模块编号不能小于0', trigger: 'blur' },
      { type: 'integer', max: 999999999, message: '模块编号太长', trigger: 'blur' }
    ],
    moduleId: [
      {required: true, message: '请选择所属模块', trigger: 'change'}
    ],
  },

};

// 和网络交互相关的参数
let params = {
  //新增或者编辑 弹出框的数据
  action: {
    id: 0,
    moduleId: 0,
    moduleName: '',
    name: '',
    sequence: 99,
    note: '',
    hiddenId:'',
    operationJson: [{
      name: '',
      note: '',
      url: '',
      isMain: false
    }

    ]
  },
  //搜索条件
  actionNameSearch: '',
  actionModuleIdSearch: '',
};

// 页面的数据源
let data = {
  actionList: [],
  moduleList: []
};

let table = {

  tableRowIndex: {
    type: 'index',
    title: '序号',
    width: 80,
    align:'center'
  },
  tableRowType:{
    title: '类型',
    key: 'type',
    width: 80,
    align:'center',
    render: (h, params) => {
      var type = params.row.type;
      var typeName = "";
      if (type===1){
        typeName = "模块";
      }
      if (type===2){
        typeName = "页面";
      }
      if (type===3){
        typeName = "功能";
      }
      return h('div',typeName);
    }
  },
  tableRowName: {
    title: '功能名称',
    key: 'name',
    align:'center',
    minWidth:150,
  },
  tableRowNumber: {
    title: '功能编号',
    key: 'code',
    width: 300,
    align:'center'
  },
  tableRowOwner: {
    title: '所属模块/页面',
    key: 'note',
    align:'center',
    minWidth:150,
    render: (h, params) => {
     var result = params.row.note+" - "+params.row.position;
      return h('div',result===' - '?'':result);
    }
  },
  tableRowSequence: {
    title: '	排序',
    width: 80,
    key: 'sequence',
    align:'center'
  },
  tableRowAction: tableRowActionEdit
};

let role = {
  actionAdd:false,
  actionEdit:false,
  actionDelete:false,
};

export  default  {
  tPage: page,
  tStatus: status,
  tParams: params,
  tTable: table,
  tData: data,
  tRole:role
};
